#include "diff.h"
float TBifCalc::det( int n, int *pr, int *pc, float *pa, int N)
{
	register int i,j;
	int pr1[10],pc1[10],r_v,c_v;
	float d;
	int sign,f_r,f_c;

	if (n==1) return *pa;
	if( n == 2)
	{
		d = *( pa + N * *pr + *pc );
		d *= *(pa+N*(*(pr+1))+(*(pc+1)));
		d -= *(pa+N*(*(pr+1))+(*pc))*(*(pa+N*(*pr)+(*(pc+1))));
		return d;
	}
	else
	{
		d = 0;
		for( i = 0; i < n; i++)
		{
			sign = ((i%2) == 0)? 1 : -1;
			f_c = f_r = 0;
				r_v = *(pr + n-1);
				c_v = *(pc + n-1);
			for( j = 0; j < n-1; j++)
			{
				if( j == 0)
				{
					r_v = *(pr + j);
					f_r = 1;
				}
				if( j == i)
				{
					f_c = 1;
					c_v = *(pc + j);
				}
				*(pr1 + j) = *(pr + j + f_r);
				*(pc1 + j) = *(pc + j + f_c);
			}
			d += sign*(*(pa + N*r_v + c_v)) * det(n-1,pr1,pc1,pa,N);
		}
	}
	return (d);
}

